/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   01.03.2010
 * @version SVN: $Id: URLStreamFactory.java 43 2010-03-27 17:45:25Z christian-kerl@web.de $
 */

package org.cakis.server.service.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * Interface defining a method to get an {@link InputStream} for a given {@link URL}.
 * Classes, which use {@link URL#openStream()} should use this interface instead so
 * mocking the {@link InputStream} in UnitTests is possible.
 * 
 * @author Christian Kerl
 */
public interface URLStreamFactory {
    /**
     * Default implementation of the {@link URLStreamFactory} interface
     * just calling {@link URL#openStream()}.
     */
    public static final URLStreamFactory DEFAULT = new URLStreamFactory() {
        @Override
        public InputStream openStream(URL url) throws IOException {
            return url.openStream();
        }
    };

    /**
     * Opens an {@link InputStream} for the given {@link URL}.
     * 
     * @param url
     * @return
     * 
     * @throws IOException
     */
    InputStream openStream(URL url) throws IOException;
}
